/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui;

import javax.microedition.lcdui.Graphics;

/**
 *
 * @author tho.hoang
 */
public class RankingItem extends ADetailItem {

    private int rank, totalRank, align;

    public RankingItem(String id, String title, int rank, int totalRank, int align) {
        super(id, title + rank + "/" + totalRank, "");
        this.rank = rank;
        this.totalRank = totalRank;
        this.align = align;
    }

    public int getRank() {
        return rank;
    }

    public void setRank(int rank) {
        this.rank = rank;
    }

    public int getTotalRank() {
        return totalRank;
    }

    public void setTotalRank(int totalRank) {
        this.totalRank = totalRank;
    }

    public void paint(int x, int y, Graphics g) {
        paint(x, y, g, false);
    }

    public void paint(int x, int y, Graphics g, boolean validate) {
        if (validate && !isPaint(x, y)) {
            return;
        }

        initItem();
        if (focus) {
            g.setColor(style.getSelectedBgColor());
            g.fillRect(getX(), getY(), width - style.getPadding().getLeftAndRight(), height);
        }

        int i = 0, tempX = 0, tempY = 0;
        if (align != ALIGN_LEFT && align != ALIGN_CENTER && align != ALIGN_RIGHT) {
            align = ALIGN_LEFT;
        }

        if (align == ALIGN_LEFT) {
            // paint title
            if (title.length() > 0) {
                tempX = getX() + style.getPadding().getLeft() + titleStyle.getPadding().getLeft();
                tempY = getY() + style.getPadding().getTop() + titleStyle.getPadding().getTop();
                for (i = 0; i < titleRows.length; i++) {
                    font.getFontBold().drawString(g, titleRows[i], tempX, tempY + i * (font.getFontBold().getHeight() + titleStyle.getRowHeight()), Graphics.TOP | Graphics.LEFT);
                }
            }

        } else if (align == ALIGN_RIGHT) {
            // paint title
            if (title.length() > 0) {
                tempX = width - style.getPadding().getRight() - titleStyle.getPadding().getRight();
                tempY = getY() + style.getPadding().getTop() + titleStyle.getPadding().getTop();
                for (i = 0; i < titleRows.length; i++) {
                    font.getFontBold().drawString(g, titleRows[i], tempX, tempY + i * (font.getFontBold().getHeight() + titleStyle.getRowHeight()), Graphics.TOP | Graphics.LEFT);
                }
            }

        } else if (align == ALIGN_CENTER) {
            // paint title
            if (title.length() > 0) {
                tempX = width / 2 + style.getPadding().getLeft();
                tempY = getY() + style.getPadding().getTop() + titleStyle.getPadding().getTop();
                for (i = 0; i < titleRows.length; i++) {
                    font.getFontBold().drawString(g, titleRows[i], tempX, tempY + i * (font.getFontBold().getHeight() + titleStyle.getRowHeight()), Graphics.TOP | Graphics.LEFT);
                }
            }
        }
    }
}
